
import { storeToRefs } from "pinia";
import router from "@/router/index.js"
import { useUserStore } from "@/stores/user.js"



export default {
    install:function(app){
        // console.log(3333);
        
        let User = useUserStore();
        
        let { isLogin, userid } = storeToRefs(User);
        
        app.config.globalProperties.isLogin = isLogin; // ref对象
        app.config.globalProperties.toLogin = ()=>{
            // console.log(4444, router);

            // router.currentRoute => ref(route)
            if(!isLogin.value){
                router.replace({ name: "login", query: { ReturnUrl: encodeURIComponent(router.currentRoute.value.fullPath) } })
            }
        } 

    }
}